/**
 * 栈的数组实现
*/
#include <stdlib.h>

#ifndef STACK_ARRAY
#define STACK_ARRAY

#ifndef StackElementType
#define StackElementType int
#endif

typedef struct Stack Stack;
struct Stack {
    StackElementType* data;
    int top;
    int capacity;
};

Stack* createStack(int capacity) {
    Stack* s = calloc(1, sizeof(Stack));
    s->data = calloc(capacity, sizeof(StackElementType));
    s->capacity = capacity;
    s->top = 0;
    return s;
}

void freeStack(Stack* stack) {
    free(stack->data);
    free(stack);
}

int isStackEmpty(Stack* s) {
    return s->top == 0;
}

int isStackFull(Stack* s) {
    return s->top >= s->capacity;
}

StackElementType peekFirst(Stack* s) {
    return s->data[s->top];
}

int pushStack(Stack* s, StackElementType value) {
    if (isStackFull(s)) {
        printf("Stack Full\n");
        return 0;
    }
    s->data[++(s->top)] = value;
    return 1;
}

StackElementType popStack(Stack* s) {
    return s->data[(s->top)--];
}

#endif 
